package com.hehao.java_basic.stream;


import com.hehao.common.entiy.Person;

import java.util.Comparator;
import java.util.List;

/**
 * @author Damon
 * @date 2022/2/23
 * stream的聚合操作，max  min  count
 */
public class MaxMinCountDemo {
    public static void main(String[] args) {
        List<Person> list = Person.getList();
        //自定义排序规则
        System.out.println(list.stream().max(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getSalary().compareTo(o2.getSalary());
            }
        }).get());
        System.out.println("==========================");

        //自然排序
        System.out.println(list.stream().max(Comparator.comparingInt(Person::getSalary)).get());
        System.out.println("==========================");

        //count
        System.out.println(list.stream().filter(x -> x.getSalary() > 8000).count());

    }
}
